package com.zctest.service.impl;

import com.zctest.CommonException;
import com.zctest.dao.UserRepository;
import com.zctest.entity.Book;
import com.zctest.entity.Company;
import com.zctest.entity.User;
import com.zctest.service.BookService;
import com.zctest.service.CompanyService;
import com.zctest.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhangchao
 * @version 1.0
 * @date 2019/1/7
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private BookService bookService;
    @Autowired
    private CompanyService companyService;
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Transactional
    @Override
    public void save(User user) {
        userRepository.save(user);
    }

    @Override
    @Transactional
    public void saveTogether(User user) {
        logger.info("进入、api/a 保存");
        logger.info("测试Git1");
        userRepository.save(user);
        logger.info("测试Git2");
		logger.info("测试Git3");

        try {
            bookService.save(new Book());
        } catch (CommonException e) {
            e.printStackTrace();
            logger.error("捕获到的异常信息{}",e.getMessage());
        }
        List<User> all = userRepository.findAll();

        companyService.save(new Company());
        logger.info("保存成功");
    }
    private void test(){
        logger.info("测试Git4");
    }
}
